package orion.cricScoreCard.Activity;

import orion.cricScoreCard.Entities.CurrentPlayers;
import orion.cricScoreCard.Entities.Match;
import orion.cricScoreCard.Entities.Teams;
import orion.cricScoreCard.Utilities.ScoringFunctions;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class TeamDetails extends Activity implements OnClickListener {

	private EditText _striker;
	private EditText _nonStriker;
	private EditText _bowler;
	private TextView _txtBatting;
	private TextView _txtBowling;
	private Button _btnTeam;
	Match _match;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.batting);
		init();
		_btnTeam.setOnClickListener(this);

	}

	private void init() {
		_striker = (EditText) findViewById(R.id.edittxtPlayer1);
		_nonStriker = (EditText) findViewById(R.id.editTxtPlayer2);
		_bowler = (EditText) findViewById(R.id.edittxtBowler);
		_txtBatting = (TextView) findViewById(R.id.txtBatting);
		_txtBowling = (TextView) findViewById(R.id.txtBowling);
		_btnTeam = (Button) findViewById(R.id.btnBatting);
		Intent teamInt = getIntent();
		Bundle teamBundle = teamInt.getExtras();
		_match = new Match(teamBundle.getString("Batting"),
				teamBundle.getString("Bowling"), Integer.parseInt(teamBundle
						.getString("Overs")));
		ScoreCard.setMatch(_match);
		ScoringFunctions.setBalls(Integer.parseInt(teamBundle
				.getString("Overs")));
		_txtBatting.setText(teamBundle.getString("Batting"));
		_txtBowling.setText(teamBundle.getString("Bowling"));
	}

	@Override
	public void onClick(View v) {
		CurrentPlayers.setStriker(_striker.getText().toString());
		CurrentPlayers.setNon_striker(_nonStriker.getText().toString());
		CurrentPlayers.setBowler(_bowler.getText().toString());
		Teams teams = new Teams();
		teams.addPlayer(_striker.getText().toString(), "Batsman");
		teams.addPlayer(_nonStriker.getText().toString(), "Batsman");
		teams.addPlayer((_bowler.getText().toString()), "Bowler");
		Intent scoreInt = new Intent(this, ScoreCard.class);
		startActivity(scoreInt);
	}
}
